package com.blog.utils;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class ResponseResult implements Serializable {
    private ResponseResult(){}
    //"是否成功"
    private Boolean success;
    //"状态码"
    private Integer code;
    //"返回消息"
    private String message;
    // "返回的数据"
    private Map<String,Object> data = new HashMap<>();

    /*提供工具方法*/
    public static ResponseResult ok(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setSuccess(true);
        responseResult.setCode(ResultCode.SUCCESS);
        responseResult.setMessage("成功");
        return responseResult;
    }
    public static ResponseResult error(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setSuccess(false);
        responseResult.setCode(ResultCode.ERROR);
        responseResult.setMessage("失败");
        return responseResult;
    }

    public ResponseResult success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public ResponseResult message(String message){
        this.setMessage(message);
        return this;
    }
    public ResponseResult code(Integer code){
        this.setCode(code);
        return  this;
    }
    public ResponseResult data(String key,Object value){
        this.data.put(key,value);
        return this;
    }
    public ResponseResult data(Map<String,Object> map){
        this.setData(map);
        return this;
    }

}
